home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
gfx
/
edit
/
TSMrph23s.lha
/
TSM23s.lha
/
HandleSettings.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-08
|
25KB
|
845 lines
// TSMorph - Amiga Morphing program
// Copyright (C) © 1993 Topicsave Limited
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// mpaddock@cix.compulink.co.uk
// $Author: M_J_Paddock $
// $Date: 1993/09/04 17:45:18 $
// $Revision: 1.10 $
// include precompiled headers (if not already)
#ifndef TSMORPH_H
#include "TSMorph.h"
#endif
/* Remove menus from all windows allowing
* them to be updated
*/
void
RemoveMenus(void) {
if (TSMorphWnd) {
ClearMenuStrip(TSMorphWnd);
}
if (ControlWindow) {
ClearMenuStrip(Pic1.Win);
ClearMenuStrip(Pic2.Win);
ClearMenuStrip(ControlWindow);
}
}
/* Add the menus back again after
* calling RemoveMenus() and updating
*/
void
AddMenus(void) {
if (TSMorphWnd) {
ResetMenuStrip(TSMorphWnd,TSMorphMenus);
}
if (ControlWindow) {
ResetMenuStrip(ControlWindow,MyMenu);
ResetMenuStrip(Pic1.Win,MyMenu);
ResetMenuStrip(Pic2.Win,MyMenu);
}
}
/* Update the save format menu items
* Parameter: remove - set to TRUE to remove and add the menus
* to FALSE if menus have already been removed (for lots of updates)
*/
void
UpdateSaveFormat(BOOL remove) {
if (remove) {
RemoveMenus();
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
}
if (remove) {
AddMenus();
}
}
/* Update the render mode menu items
* see UpdateSaveFormat() for parameter
*/
void
UpdateRenderMode(BOOL remove) {
if (remove) {
RemoveMenus();
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE0)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE3)))->Flags &= ~CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE0)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE3)))->Flags &= ~CHECKED;
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,RenderMode)))->Flags |= CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,RenderMode)))->Flags |= CHECKED;
}
if (remove) {
AddMenus();
}
}
/* Update the open mode menu items
* see UpdateSaveFormat() for parameter
*/
void
UpdateOpenMode(BOOL remove) {
if (remove) {
RemoveMenus();
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
}
if (TSMorphWnd) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
}
if (ControlWindow) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
}
if (remove) {
AddMenus();
}
}
/* UnZoom the image windows
* i.e. currently displayed 2x and
* want to display 1x
*/
void
UnZoom(void) {
// Already zoomed - set number of windows resized (change window box may not work)
// see the main loop on how the messages are then handled
changedboxcount = 0;
// Copy image 1 to superbitmap and resync
BltBitMap(Pic1.ilbm->brbitmap,0,0,&(Pic1.BitMap),0,0,Pic1.ilbm->Bmhd.w,Pic1.ilbm->Bmhd.h,0xC0,0xff,NULL);
LockLayerRom(Pic1.Win->RPort->Layer);
CopySBitMap(Pic1.Win->RPort->Layer);
UnlockLayerRom(Pic1.Win->RPort->Layer);
/* Resize gadgets and window (if too big)
* Window limits are reset and points
* redrawn with IDCMP_CHANGEWINDOW
*/
SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
PGA_Total, Pic1.ilbm->Bmhd.w,
TAG_END);
SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
PGA_Total, Pic1.ilbm->Bmhd.h,
TAG_END);
ChangeWindowBox(Pic1.Win,Pic1.Win->LeftEdge,Pic1.Win->TopEdge,
min(Pic1.Win->Width,Pic1.ilbm->Bmhd.w+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n)),
min(Pic1.Win->Height,Pic1.ilbm->Bmhd.h+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
// Do the same of image/window2
BltBitMap(Pic2.ilbm->brbitmap,0,0,&(Pic2.BitMap),0,0,Pic2.ilbm->Bmhd.w,Pic2.ilbm->Bmhd.h,0xC0,0xff,NULL);
LockLayerRom(Pic2.Win->RPort->Layer);
CopySBitMap(Pic2.Win->RPort->Layer);
UnlockLayerRom(Pic2.Win->RPort->Layer);
SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
PGA_Total, Pic2.ilbm->Bmhd.w,
TAG_END);
SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
PGA_Total, Pic2.ilbm->Bmhd.h,
TAG_END);
ChangeWindowBox(Pic2.Win,Pic2.Win->LeftEdge,Pic2.Win->TopEdge,
min(Pic2.Win->Width,Pic2.ilbm->Bmhd.w+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n)),
min(Pic2.Win->Height,Pic2.ilbm->Bmhd.h+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
// Wait till its all done (why?) and reset Zoom
WaitBlit();
Zoom = 0;
}
/* Zoom the image windows
* i.e. currently displayed 1x and
* want to display 2x
*/
void
ReZoom(void) {
/* Currently normal size
* scale image 1, set window max size
* redo gadgets and copy to superbitmap
*/
BitMapScale(&(Pic1.BitScaleArgs));
WindowLimits(Pic1.Win,0,0,(Pic1.ilbm->Bmhd.w<<1)+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n),
(Pic1.ilbm->Bmhd.h<<1)+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
PGA_Total, Pic1.ilbm->Bmhd.w<<1,
TAG_END);
SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
PGA_Total, Pic1.ilbm->Bmhd.h<<1,
TAG_END);
LockLayerRom(Pic1.Win->RPort->Layer);
CopySBitMap(Pic1.Win->RPort->Layer);
UnlockLayerRom(Pic1.Win->RPort->Layer);
// Same for image 2
BitMapScale(&(Pic2.BitScaleArgs));
WindowLimits(Pic2.Win,0,0,(Pic2.ilbm->Bmhd.w<<1)+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n),
(Pic2.ilbm->Bmhd.h<<1)+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
PGA_Total, Pic2.ilbm->Bmhd.w<<1,
TAG_END);
SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
PGA_Total, Pic2.ilbm->Bmhd.h<<1,
TAG_END);
LockLayerRom(Pic2.Win->RPort->Layer);
CopySBitMap(Pic2.Win->RPort->Layer);
UnlockLayerRom(Pic2.Win->RPort->Layer);
/* Reset Zoom, Check new size gadgets,
* and redraw all the points
*/
Zoom = 1;
doNewSize(&Pic1);
doNewSize(&Pic2);
DrawAllPoints();
}
/* switch the check mark of a settings menu item
* Parameters: pos position in the settings menu
* settings TRUE or FALSE
* remove remove and add menus? see UpdateSaveFormat()
*/
void
SwitchMenuItem(UWORD pos,BOOL setting,BOOL remove) {
if (remove) {
RemoveMenus();
}
if (TSMorphWnd) {
if (setting) {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags |= CHECKED;
}
else {
(ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags &= ~CHECKED;
}
}
if (ControlWindow) {
if (setting) {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags |= CHECKED;
}
else {
(ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags &= ~CHECKED;
}
}
if (remove) {
AddMenus();
}
}
/* Handle Settings menu messages
* Parameters: Selection the item number
* pic the current picture
*/
void
HandleSettings(UWORD Selection,struct Picture *pic) {
ULONG OZoom; // The old zoom mode
// switch on the selection
switch(ITEMNUM(Selection)) {
case MM_ICONS:
// Toggle Create Icons?
CreateIcons = !CreateIcons;
SwitchMenuItem(MM_ICONS,CreateIcons,TRUE);
break;
case MM_PALETTE:
// Toggle Change Palette? - Uncolor the current image if we have one
if (palette && pic) {
UnColorWindow(pic);
}
palette = !palette;
SwitchMenuItem(MM_PALETTE,palette,TRUE);
break;
case MM_ZOOM:
// Toggle Zoom?
if (ControlWindow) {
// UnZoom or ReZoom the images if open
DisableWindows(DI_Zoom);
if (Zoom) {
UnZoom();
}
else {
ReZoom();
}
EnableWindows();
}
else {
if (Zoom) {
Zoom = 0;
}
else {
Zoom = 1;
}
}
SwitchMenuItem(MM_ZOOM,Zoom,TRUE);
break;
case MM_OPENMODE:
// Set new open mode
OpenMode = SUBNUM(Selection);
UpdateOpenMode(TRUE);
break;
case MM_SCREEN:
// Get public screen name
GetAString("Public Screen",ScreenName,H_P_PS);
break;
case MM_CUSTOM:
// Get custom screen mode
GetAString("Custom Screen Mode",CustomName,H_PCUSTM);
break;
case MM_CDEPTH:
// Get custom screen depth
GetANumber("Custom Screen Depth",&CustomDepth,H_PCUSTD);
break;
case MM_SPREVIEW:
// Get preview script
GetAString("Preview Script",PreviewScript,H_P_Preview);
break;
case MM_ICONSP:
// Toggle Create prefs Icons?
CreateIconsP = !CreateIconsP;
SwitchMenuItem(MM_ICONSP,CreateIconsP,TRUE);
break;
case MM_KEEPS:
// Toggle Keep Settings?
KeepSettings = !KeepSettings;
SwitchMenuItem(MM_KEEPS,KeepSettings,TRUE);
case MM_LOADS:
// Load new settings from requester
LoadSettings(NULL);
break;
case MM_SAVES:
// Save settings to ENV: and ENVARC:
SaveSettings("ENVARC:TSMorph/TSMorph.prefs");
SaveSettings("ENV:TSMorph/TSMorph.prefs");
break;
case MM_SAVESAS:
// save settings from requester
SaveSettings(NULL);
break;
case MM_ICONSR:
// Toggle Create render Icons?
CreateIconsR = !CreateIconsR;
SwitchMenuItem(MM_ICONSR,CreateIconsR,TRUE);
break;
case MM_DX:
// Get DX
GetANumber("DX",&DX,H_P_DX);
break;
case MM_DY:
// Get DY
GetANumber("DY",&DY,H_P_DY);
break;
case MM_LOADSCRIPT:
// Get load script
GetAString("Load Script",LoadScript,H_P_LS);
break;
case MM_PRESCRIPT:
// Get pre script
GetAString("Pre Script",PreScript,H_P_PES);
break;
case MM_POSTSCRIPT:
// Get post script
GetAString("Post Script",PostScript,H_P_POS);
break;
case MM_DEPTH:
// Get depth
GetANumber("Depth",&Depth,H_P_DE);
break;
case MM_RENDERMODE:
// Set new render mode
RenderMode = SUBNUM(Selection);
UpdateRenderMode(TRUE);
break;
case MM_SAVEFORMAT:
// Set new save format
SaveFormat = SUBNUM(Selection);
UpdateSaveFormat(TRUE);
break;
case MM_QUALITY:
// Get quality
GetANumber("Quality",&Quality,H_P_QU);
break;
case MM_SCREENR:
// Get render public screen
GetAString("Render Screen",ScreenNameR,H_P_PSR);
break;
case MM_ANTIALIAS:
// Toggle Anti-Alias?
AntiAlias = !AntiAlias;
SwitchMenuItem(MM_ANTIALIAS,AntiAlias,TRUE);
break;
case MM_RESETD:
// Reset to default prefs
OZoom = Zoom; // keep current zoom
if (!ControlWindow) {
// if the images are open then we can not change these
PaletteAllowed = TRUE;
ZoomAllowed = TRUE;
}
// Set all other settings to defaults
ScreenName[0] = 0;
ScreenNameR[0] = 0;
CreateIcons = TRUE;
CreateIconsR = FALSE;
CreateIconsP = TRUE;
KeepSettings = TRUE;
if (PaletteAllowed) {
palette = TRUE;
}
else {
palette = FALSE;
}
Zoom = 0;
OpenMode = OPEN_ILBM_IF_COLOURS;
SaveFormat = MI_ILBM24;
Quality = 75;
strcpy(PreScript,"Rexx/Prescript");
strcpy(PostScript,"Rexx/Postscript");
strcpy(LoadScript,"Rexx/Loadscript");
strcpy(PreviewScript,"Rexx/Preview");
DX = 0;
DY = 0;
Depth = 2;
RenderMode = 0;
CustomName[0] = 0;
CustomDepth = 4;
UpdateParams(OZoom);
break;
case MM_LASTS:
// Load settings from ENVARC:
LoadSettings("ENVARC:TSMorph/TSMorph.prefs");
break;
case MM_RESTORE:
// Load settings from ENV:
LoadSettings("ENV:TSMorph/TSMorph.prefs");
break;
case MM_HELP:
// Toggle Help?
GHelp = !GHelp;
SwitchMenuItem(MM_HELP,GHelp,TRUE);
break;
default:
// something else ??
break;
}
}
/* Request a number from the user using reqtools.library
* Parameters: title - title of requester
* number - address of number to display and get
* HelpNum - help key if help required
*/
void
GetANumber(char *title,ULONG *number,ULONG HelpNum) {
ULONG ret = 2; // current gadget
struct AmigaGuideMsg *agm; // amiga guide stuff
ULONG signals; // signals to wait on
struct rtHandlerInfo *rth; // reqtools stuff
// disable all the windows
DisableWindows(HelpNum);
// loop until Ok or Cancel pressed
while (ret == 2) {
ret = CALL_HANDLER;
if (rtGetLong(number,title,NULL,
RT_ReqHandler, &rth,
RT_Window, TSMorphWnd,
RTGL_ShowDefault, TRUE,
RT_Underscore, '_',
RTGL_GadFmt, handle?"_OK|_Help|_Cancel":"_OK|_Cancel", // if amigaguide then help gadget
TAG_END) == CALL_HANDLER) {
while (ret == CALL_HANDLER) {
if (!rth->DoNotWait) {
// wait if possible
signals = Wait(rth->WaitMask | ASig);
}
ret = rtReqHandlerA(rth,signals,NULL);
if (ret == 2) {
// display help if requested, 2 is only possible if help gadget is available
help(HelpNum);
}
if (signals & ASig) {
// do amigaguide stuff
while (agm = GetAmigaGuideMsg(handle)) {
ReplyAmigaGuideMsg(agm);
}
}
}
}
}
// re-enable all the windows
EnableWindows();
}
/* Request a string from the user using reqtools.library
* Parameters: title - title of requester
* number - address of buffer to display and get
* HelpNum - help key if help required
* See GetANumber for comments
*/
void
GetAString(char *title,char *buffer,ULONG HelpNum) {
ULONG ret = 2;
struct AmigaGuideMsg *agm;
ULONG signals;
struct rtHandlerInfo *rth;
DisableWindows(HelpNum);
while (ret == 2) {
ret = CALL_HANDLER;
if (rtGetString(buffer,127,title,NULL,
RT_ReqHandler, &rth,
RT_Window, TSMorphWnd,
RTGL_ShowDefault, TRUE,
RT_Underscore, '_',
RTGL_GadFmt, handle?"_OK|_Help|_Cancel":"_OK|_Cancel",
RTGS_AllowEmpty, TRUE,
TAG_END) == CALL_HANDLER) {
while (ret == CALL_HANDLER) {
if (!rth->DoNotWait) {
signals = Wait(rth->WaitMask | ASig);
}
ret = rtReqHandlerA(rth,signals,NULL);
if (ret == 2) {
help(HelpNum);
}
if (signals & ASig) {
while (agm = GetAmigaGuideMsg(handle)) {
ReplyAmigaGuideMsg(agm);
}
}
}
}
}
EnableWindows();
}
/* Save the current settings
* Parameters: filename - filename to save to
* or NULL for requester
*/
void
SaveSettings(char *filename) {
char *ifilename = NULL; // the actual file name
BPTR fh; // file handle
BOOL ok = TRUE; // Is it working?
char buffer[65]; // buffer for records
struct DiskObject *MyDiskObject; // The Icon
// Disable all windows
DisableWindows(DI_WaitSS);
// if no file name supplied then request a name
if (!filename) {
if (GetAFile("TSMorph.prefs","Save Settings",FILF_SAVE)) {
ifilename = TempFilename;
}
}
else {
ifilename = filename;
}
// if we now a file name
if (ifilename) {
// try and open the file
if (fh = Open(ifilename,MODE_NEWFILE)) {
// save all TSMorph settings
FPuts(fh,";TSMorph parameters\n");
FPuts(fh,"CREATEICONS=");
FPuts(fh,CreateIcons?"YES\n":"NO\n");
FPuts(fh,"CHANGEPALETTE=");
FPuts(fh,(!PaletteAllowed)?"OFF\n":(palette?"YES\n":"NO\n"));
FPuts(fh,"ZOOM=");
FPuts(fh,(!ZoomAllowed)?"OFF\n":(Zoom?"YES\n":"NO\n"));
FPuts(fh,"OPENMODE=");
switch (OpenMode) {
case OPEN_ILBM_IF_ILBM:
FPuts(fh,"IFILBM\n");
break;
case OPEN_ILBM_ALWAYS:
FPuts(fh,"ALWAYS\n");
break;
case OPEN_REMAP:
FPuts(fh,"REMAP\n");
break;
case OPEN_OPAL:
FPuts(fh,"OPAL\n");
break;
case OPEN_ILBM_IF_COLOURS:
default:
FPuts(fh,"IFCOLOURS\n");
break;
}
if (*ScreenName) {
FPuts(fh,"PUBSCREEN=");
FPuts(fh,ScreenName);
FPuts(fh,"\n");
}
else {
FPuts(fh,";PUBSCREEN=\n");
}
if (*CustomName) {
FPuts(fh,"CUSTOMMODE=");
FPuts(fh,CustomName);
FPuts(fh,"\n");
}
else {
FPuts(fh,";CUSTOMMODE=\n");
}
sprintf(buffer,"CUSTOMDEPTH=%ld\n",CustomDepth);
FPuts(fh,buffer);
FPuts(fh,"PREVIEW=");
FPuts(fh,PreviewScript);
FPuts(fh,"\n");
FPuts(fh,"HELP=");
FPuts(fh,GHelp?"YES\n":"NO\n");
// Save all prefs settings
FPuts(fh,";Prefs parameters\n");
FPuts(fh,"CREATEICONSP=");
FPuts(fh,CreateIconsP?"YES\n":"NO\n");
FPuts(fh,"KEEPSETTINGS=");
FPuts(fh,KeepSettings?"YES\n":"NO\n");
// Save all render settings
FPuts(fh,";TSMorph-render parameters\n");
FPuts(fh,"CREATEICONSR=");
FPuts(fh,CreateIconsR?"YES\n":"NO\n");
sprintf(buffer,"DX=%ld\n",DX);
FPuts(fh,buffer);
sprintf(buffer,"DY=%ld\n",DY);
FPuts(fh,buffer);
FPuts(fh,"LOADSCRIPT=");
FPuts(fh,LoadScript);
FPuts(fh,"\n");
FPuts(fh,"PRESCRIPT=");
FPuts(fh,PreScript);
FPuts(fh,"\n");
FPuts(fh,"POSTSCRIPT=");
FPuts(fh,PostScript);
FPuts(fh,"\n");
sprintf(buffer,"DEPTH=%ld\n",Depth);
FPuts(fh,buffer);
sprintf(buffer,"MODE=%ld\n",RenderMode);
FPuts(fh,buffer);
FPuts(fh,"SAVEFORMAT=");
switch (SaveFormat) {
case MI_OPAL24:
FPuts(fh,"OPAL24\n");
break;
case MI_OPAL24T:
FPuts(fh,"OPAL24T\n");
break;
case MI_OPAL24F:
FPuts(fh,"OPAL24F\n");
break;
case MI_OPAL24FT:
FPuts(fh,"OPAL24FT\n");
break;
case MI_JPEG:
FPuts(fh,"JPEG\n");
break;
case MI_JPEGT:
FPuts(fh,"JPEGT\n");
break;
case MI_PBM:
FPuts(fh,"PPM\n");
break;
case MI_BW16:
FPuts(fh,"BW16\n");
break;
case MI_BW256:
FPuts(fh,"BW256\n");
break;
case MI_HAM6:
FPuts(fh,"HAM6\n");
break;
case MI_HAM8:
FPuts(fh,"HAM8\n");
break;
case MI_DCTV3:
FPuts(fh,"DCTV3\n");
break;
case MI_DCTV4:
FPuts(fh,"DCTV4\n");
break;
case MI_ILBM24:
default:
FPuts(fh,"ILBM24\n");
break;
}
sprintf(buffer,"QUALITY=%ld\n",Quality);
FPuts(fh,buffer);
if (*ScreenNameR) {
FPuts(fh,"PUBSCREENR=");
FPuts(fh,ScreenNameR);
FPuts(fh,"\n");
}
else {
FPuts(fh,";PUBSCREENR=\n");
}
FPuts(fh,"ANTIALIAS=");
FPuts(fh,AntiAlias?"YES\n":"NO\n");
// If want to save prefs Icon
if (CreateIconsP) {
if (MyDiskObject = GetDiskObject(ifilename)) {
// Icon already present so do not overwrite
FreeDiskObject(MyDiskObject);
}
else {
// Try and get an icon and write it
if ((MyDiskObject = GetDiskObject("ENV:TSMorph/def_prefs")) ||
(MyDiskObject = GetDiskObject("ENV:SYS/def_prefs")) ||
(MyDiskObject = GetDefDiskObject(WBPROJECT))) {
PutDiskObject(ifilename,MyDiskObject);
FreeDiskObject(MyDiskObject);
}
}
}
// try and close the file
if (!Close(fh)) {
ok = FALSE;
}
}
else {
ok = FALSE;
}
}
// enable the windows and display error if required
EnableWindows();
if (!ok) {
Error("Error Saving Settings '%s'","OK",ifilename,HE_SaveSettings);
}
}
/* Load the current settings
* Parameters: filename - filename to load from
* or NULL for requester
*/
void
LoadSettings(char *filename) {
BPTR fh; // file handle
int kount = 0; // count of lines
int kount1 = 0; // index
BOOL ok = TRUE; // Still ok?
char string[65]; // record buffer
char *ifilename = NULL; // actual filename
// if no file name then show requester
if (!filename) {
if (GetAFile("TSMorph.prefs","Load Settings",0)) {
ifilename = TempFilename;
}
}
else {
ifilename = filename;
}
// if we now have a file name...
// see Args.c MyArgArrayInit() for more info
if (ifilename) {
if (ArgArraySettings) {
FreeVec(ArgArraySettings);
ArgArraySettings = NULL;
}
if (fh = Open(ifilename,MODE_OLDFILE)) {
// If we have found a file the relevant lines
while (FGets(fh,string,64)) {
if ((string[0] != '\n') &&
(string[0] != ';')) {
++kount;
}
}
Close(fh);
if (fh = Open(ifilename,MODE_OLDFILE)) {
// Allocate memory for settings from file pointers
if (ArgArraySettings = AllocVec((kount+1) * sizeof(UBYTE *),MEMF_CLEAR)) {
// Read in all settings
while (FGets(fh,string,64) &&
(kount1 < kount)) {
// remove newline
string[strlen(string)-1] = '\0';
// ignore blank and comment lines
if (string[0] && (string[0]!=';')) {
// Clone settings in memory
ArgArraySettings[kount1] = strdup(string);
++kount1;
}
}
// reset up the new settings
InitParams(TRUE);
}
else {
ok = FALSE;
}
Close(fh);
}
else {
ok=FALSE;
}
}
else {
ok=FALSE;
}
}
if (!ok) {
Error("Error Loading Settings '%s'","OK",ifilename,HE_LoadSettings);
}
}